<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<!-- <el-form-item>
					<el-input v-model="filters.name" placeholder="设备IP"></el-input>
				</el-form-item> -->
				<el-form-item>
					<el-button type="primary" @click="screenEdit">查询</el-button>
				</el-form-item>
				<el-date-picker
			      v-model="exprotDate"
			      type="daterange"
      			  range-separator="至"
			      placeholder="请选择开始和结束时间">
			    </el-date-picker>
				<el-form-item v-show="my_permi.indexOf('weightdata.export') > -1 || my_permi.indexOf('admin') > -1">
					<el-button type="primary" @click="exportT">导出</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="tableList" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="clientHeight" >
			<el-table-column prop="ic_id" label="IC卡卡号" width="80">
			</el-table-column>
			<el-table-column prop="system_datetime" label="系统时间" width="80">
			</el-table-column>
			<el-table-column prop="trans_status_desc" label="单据类型" width="60">
			</el-table-column>
			<el-table-column prop="trans_type_desc" label="单据状态" width="60">
			</el-table-column>
			<el-table-column prop="vehicle_number" label="车牌号码" width="100">
			</el-table-column>
			<el-table-column prop="is_finished_desc" label="是否完成" width="60">
			</el-table-column>
			<el-table-column prop="site_code" label="称重计量地点" width="100">
			</el-table-column>
			<el-table-column label="初称信息" width="60">
				<template slot-scope="scope">
					<el-button size="small" type="primary" @click="viewDetails1(scope.$index)">查看</el-button>
				</template>
			</el-table-column>
			<el-table-column label="回称信息" width="60">
				<template slot-scope="scope">
					<el-button size="small" type="primary" @click="viewDetails2(scope.$index)">查看</el-button>
				</template>
			</el-table-column>
			<el-table-column prop="net_weight" label="净重" width="60">
			</el-table-column>
			<el-table-column prop="actual_weight" label="吊秤重量（实际重量）" width="140">
			</el-table-column>
			<el-table-column prop="weight_error" label="误差重量" width="60">
			</el-table-column>
			<el-table-column prop="weight_error_ratio" label="误差比值" width="60">
			</el-table-column>
			<el-table-column prop="remarks" label="备注">
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination
				layout="prev, pager, next"
				@current-change="handleCurrentChange"
				:total="total"
				style="float:right;">
			</el-pagination>
		</el-col>

		<!--查看初称、回称界面-->
		<el-dialog title="初次称重信息" v-model="detailsVisible" :close-on-click-modal="false">
			<div class="weightD"><span>初称刷卡时间：</span> <span>{{details.first_readic_datetime}}</span></div>
			<div class="weightD"><span>初称重量：</span> <span>{{details.first_weight}}</span></div>
			<div class="weightD"><span>初称地磅编号：</span> <span>{{details.first_wbid}}</span></div>
			<div class="weightD"><span>初称车辆抓拍图片：</span> <img :src="details.first_capvh_path +'/'+ details.first_capvh_filename" @click="isZoom(details.first_capvh_path +'/'+ details.first_capvh_filename)"></div>
			<div class="weightD"><span>初称地磅抓拍A：</span> <img :src="details.first_cap_a_path +'/'+ details.first_cap_a_fielname" @click="isZoom(details.first_cap_a_path +'/'+details.first_cap_a_fielname)"></div>
			<div class="weightD"><span>初称地磅抓拍B：</span> <img :src="details.first_cap_b_path +'/'+ details.first_cap_b_fielname" @click="isZoom(details.first_cap_b_path +'/'+details.first_cap_b_fielname)"></div>
		</el-dialog>

		<!--查看初称、回称界面-->
		<el-dialog title="初次称重信息" v-model="detailsVisible2" :close-on-click-modal="false">
			<div class="weightD"><span>回称刷卡时间：</span> <span>{{details.second_readic_datetime}}</span></div>
			<div class="weightD"><span>回称重量：</span> <span>{{details.second_weight}}</span></div>
			<div class="weightD"><span>回称地磅编号：</span> <span>{{details.second_wbid}}</span></div>
			<div class="weightD"><span>回称车辆抓拍图片：</span> <img :src="details.second_capvh_path +'/'+ details.second_capvh_filename" @click="isZoom(details.second_capvh_path +'/'+details.second_capvh_filename)"></div>
			<div class="weightD"><span>回称地磅抓拍A：</span> <img :src="details.second_cap_a_path +'/'+ details.second_cap_a_fielname" @click="isZoom(details.second_cap_a_path +'/'+details.second_cap_a_fielname)"></div>
			<div class="weightD"><span>回称地磅抓拍A：</span> <img :src="details.second_cap_b_path +'/'+ details.second_cap_b_fielname" @click="isZoom(details.second_cap_b_path +'/'+details.second_cap_b_fielname)"></div>
		</el-dialog>

		<!-- 图片放大 -->
		<el-dialog title="展示图片" v-model="is_zoom_img" class="zoom-img-dialog" :close-on-click-modal="false">
			<img :src="zoom_img">
		</el-dialog>

        <!-- 筛选界面 -->
        <el-dialog title="筛选" v-model="screenFormVisible" :close-on-click-modal="false">
            <el-form :model="screenForm" label-width="110px" ref="screenForm">
                <el-form-item label="称重车辆类型">
                    <el-select
                    v-model="screenForm.vehicle_type"
                    placeholder="请选择">
                        <el-option
                          v-for="item in vehicle_type_arr"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="screenFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="screenSubmit" :loading="screenLoading">提交</el-button>
            </div>
        </el-dialog>
	</section>
</template>

<script>
	import { weightData, BASEURL } from '@/api/api';
    import { mapState } from 'vuex'
	export default {
		data() {
			return {
				filters: {
					name: ''
				},
				tableList: [],
				total: 0,
				page: 1,
				listLoading: false,
				detailsVisible: false,  //查看称重详情
				detailsVisible2: false,
				details: {},
				is_zoom_img: false,
				zoom_img: '',
				exprotDate: '',
                screenFormVisible: false,//新增界面是否显示
                screenLoading: false,
                //新增界面数据
                screenForm: {
                },
                vehicle_type_arr: [
                	{
						label: '外部车辆',
						value: 'EX',
					},
                	{
						label: '内部车辆',
						value: 'IN',
					}
                ]
			}
		},
        computed: {

            ...mapState(
                {
                  'my_permi': state => state.my_permi,
                  'clientHeight': state => state.clientHeight
                }
            )
        },
		methods: {
			router(path) {
				this.$router.push(path)
			},
			handleCurrentChange(val) {
				this.page = val;
				this.weight_data(this.screenForm);
			},
			//获取设备警报信息
			weight_data(para) {
				this.listLoading = true;
				let paras = `${this.page}`;
                if(para){
                	if(para.vehicle_type){
                		paras += `&vehicle_type=${para.vehicle_type}`;
                	}
                }
				weightData(paras).then((res) => {
					if(res.data.status.errCode == '10002'){
						sessionStorage.removeItem('token');
						this.$message({
							message: res.data.status.message,
							type: 'warning'
				        });
				        setTimeout(() =>{
				        	this.router({path: '/login'})
				        }, 1500);
						return;
					}
					this.listLoading = false
					this.total = res.data.data.total
					this.tableList = res.data.data.data
				});
			},
			// 查看初称详情
			viewDetails1(index) {
				this.detailsVisible = true
				this.details = this.tableList[index]
			},
			// 查看回称详情
			viewDetails2(index) {
				this.detailsVisible2 = true
				this.details = this.tableList[index]
			},
			isZoom(imgSrc) {
				this.zoom_img = imgSrc
				this.is_zoom_img = !this.is_zoom_img
			},
            //显示查询界面
            screenEdit: function () {
                this.screenFormVisible = true;
                this.screenForm = this.screenForm
            },
            //查询
            screenSubmit: function () {
                this.$refs.screenForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.screenLoading = true;
                            let para = Object.assign({}, this.screenForm);
                            this.screenFormVisible = false;
							this.weight_data(para);
                            this.screenLoading = false;
                        });
                    }
                });
            },
			exportT() {
				let startD = "";
				let overD = "";
				let firstDate = "";
				let secendDate = "";
				let para = this.screenForm;
				let paras = '';
				if(this.exprotDate){
					firstDate = new Date(this.exprotDate[0])
					secendDate = new Date(this.exprotDate[1])
				}else{
					firstDate = new Date();
					secendDate = new Date();
				}
                if(para){
                	if(para.vehicle_type){
                		paras += `&vehicle_type=${para.vehicle_type}`;
                	}
                }
				startD = firstDate.getFullYear() + '-' + (firstDate.getMonth()+1) + '-' + firstDate.getDate()
				overD = secendDate.getFullYear() + '-' + (secendDate.getMonth()+1) + '-' + secendDate.getDate()
				location.href=`${BASEURL}/Weightdata/Export?token=${sessionStorage.token}&start_time=${startD}&end_time=${overD + ' 23:59:59'}${paras}&pageSize=${sessionStorage.getItem('pagesize')}`;
			},
		},
		mounted() {
			this.weight_data();
		}
	}

</script>

<style>
.weightD{
	margin-bottom: 10px;
}
.weightD span{
	line-height: 60px;
    display: inline-block;
    vertical-align: middle;
}
.weightD img{
	width: 120px;
	height: 60px;
	object-fit: cover;
    display: inline-block;
    vertical-align: middle;
}
.zoom-img-dialog .el-dialog{
	width: 80vw;
	height: 80vh;
}
.zoom-img-dialog .el-dialog img{
	object-fit: cover;
	height: 65vh;
}
</style>